// pages/medical/medical.js
var common = require("../../common/common.js").common;

var WxParse = require("../../wxParse/wxParse.js");

var app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        applyModal: 0,
        applylevel: 1
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        let that = this;
        that.getInfo();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    getInfo: function() {
        let that = this;
        common.request({
            endpoint: "general/shop-set",
            method: "post",
            data: {},
            success: res => {
                wx.setNavigationBarTitle({
                    title: res.extra.title
                });
                that.setData({
                    detail: WxParse.wxParse("detail", "html", res.extra.text, that, 0),
                    makephone: res.extra.phone
                });
            }
        });
    },
    makePhone: function(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone
        });
    },
    showApplyModal: function() {
        let that = this;
        that.setData({
            applyModal: 1
        });
    },
    hideRuleModal: function() {
        let that = this;
        that.setData({
            applyModal: 0
        });
    },
    saveWord: function(e) {
        let that = this;
        var key = e.currentTarget.dataset.name;
        that.setData({
            [key]: e.detail.value
        });
    },
    apply_choice: function() {
        let that = this;
        if (!that.data.name) {
            wx.showModal({
                title: "提示",
                content: "请输入联系人!",
                showCancel: false
            });
            return false;
        }
        if (!/^1[23456789]\d{9}$/.test(that.data.phone)) {
            wx.showModal({
                title: "提示",
                content: "请输入正确的手机号码!",
                showCancel: false
            });
            return false;
        }
        if (!that.data.industry) {
            wx.showModal({
                title: "提示",
                content: "请输入所属行业!",
                showCancel: false
            });
            return false;
        }
        common.request({
            endpoint: "general/shop-apply",
            method: "post",
            data: {
                name: that.data.name,
                phone: that.data.phone,
                industry: that.data.industry
            },
            success: res => {
                wx.showToast({
                    title: "已提交申请"
                });
                that.setData({
                    applyModal: 0,
                    applylevel: 0
                });
            },
            fail(err) {
                wx.showModal({
                    content: err.message,
                    showCancel: true,
                    title: "提示"
                });
            }
        });
    }
});